package com.wthink.newMain.view

import android.app.Dialog
import android.content.Context
import android.os.Build
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.annotation.RequiresApi
import com.wthink.hzgj.R
import kotlinx.android.synthetic.main.dialog_change_up_down.*
import kotlinx.android.synthetic.main.quit_login_dialog.*

class ChangeUpLineDialog : Dialog {
    constructor(context: Context) : this(context, 0)
    constructor(context: Context, themeResId: Int) : super(context, R.style.dialog) {
        setContentView(R.layout.dialog_change_up_down)
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        iv1.isSelected = true
    }

    fun setOnclickListener(listener: View.OnClickListener) {
        if (commit !== null) {
            commit.setOnClickListener(listener)
        }
        if (back !== null) {
            back.setOnClickListener(listener)
        }

        if (iv1 !== null) {
            iv1.setOnClickListener(listener)
        }

        if (iv2 !== null) {
            iv2.setOnClickListener(listener)
        }
    }

    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
    fun setBackGround(id: Int?) {
        when (id) {
            R.id.iv1->{
                iv1.isSelected = true
                iv2.isSelected = false
                //iv1.background = context.resources.getDrawable(R.mipmap.icon_point_s)
                //iv2.background = context.resources.getDrawable(R.mipmap.icon_point_n)
                recCallBack?.callBack("上行")
            }
            R.id.iv2->{
                iv2.isSelected = true
                iv1.isSelected = false
                //iv1.background = context.resources.getDrawable(R.mipmap.icon_point_n)
                //iv2.background = context.resources.getDrawable(R.mipmap.icon_point_s)
                recCallBack?.callBack("下行")
            }
        }
    }

    fun getUpDown():Boolean{
        return iv1.isSelected
    }

    private var recCallBack: RecCallBack? = null

    fun setCallBack(callBack: RecCallBack) {
        recCallBack = callBack
    }

    interface RecCallBack {
        fun callBack(content: String)
    }

}